home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
assemblr
/
library
/
screen
/
asmlib
/
disk.doc
< prev
next >
Wrap
Text File
|
1992-06-13
|
13KB
|
444 lines
***************************** DISK & FILE *******************************
ASMLIB disk & file subroutines (c) Copyright 1991 Douglas Herr
All rights reserved
The MS-DOS file attribute byte tells you whether a file is read-only,
system, a subdirectory, or may provide other information. File attribute
bits may be combined. Each bit of the file attribute means:
0 = normal files
1 = read-only
2 = hidden files
4 = system files
8 = volume label (only one per disk)
16 = subdirectories
32 = archive bit set
Thus a file with an attribute of 18 is a hidden subdirectory (16 OR 2)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
DISKWP: determines if a floppy disk is write-protected
Source: diskwp.asm
Call with: DL = floppy disk number (drive A: = 0)
Returns: AL = BIOS error code
0 = no error
1 = invalid disk number
3 = disk is write-protected
128 = drive not ready
Uses: AX, flags
Example:
include asm.inc
public mycode
extrn diskwp:proc
.code
diskwp proc
.
.
.
mov dl,1 ; drive B:
call diskwp ; can I write to this disk?
or al,al
jz no_problem
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FCOPY: copy a file
FCOPYM: copy a file using supplied memory buffer
Source: fcopy.asm
Call with: DS:[SI] = address of source filename
ES:[DI] = address of destination filename
Both filenames must be ASCIIZ strings. Drive and path need
not be fully specified; filenames may not include * or ?
wildcards.
FCOPY only: Requires 64k DOS memory available
FCOPYM only: AX = segment address of 64k buffer
Returns: if CF = 0, no problem
if CF = 1, AX = DOS error code (AX = -1 if insufficient memory)
Uses: AX, CF
Example:
.data
db 'b:'
source db 'asmlib.lib',0 ; copy the library to b:
extrn fcopy:proc
.code
; program fragment assumes DS:@data
.
.
push ds
pop es
assume es:@data
lea si,source
mov di,si ; DI also points to source
sub di,2 ; back the pointer to the 'B:'
call fcopy
jc oops
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FCOUNT: counts the number of files matching an ASCIIZ filespec string.
The filespec string may include the '*' and '?' wildcards.
Source: fcount.asm
Call with: DS:[DX] pointing to filespec string
CX = file attributes
assumes DS:@data
Returns: AX = number of files matching the filespec string
Uses: AX, all other registers and flags are saved
Example:
.code
; program fragment assumes DS:@data
.
.
.
lea dx,filespec ; address of filespec string
xor cx,cx ; normal files only
call fcount
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FEXIST: determines if a file exists and can be opened with read access
Source: fexist.asm
Call with: DS:[DX] pointing to ASCIIZ filename
Returns: if CF = 0, file exists
if CF = 1, AX = MS-DOS error code
Uses: AX, CF; all other flags and registers are saved
Example:
include asm.inc
extrn fexist:proc
.data
filename db 'asmlib.doc',0
.code
; program fragment assumes DS:@data
.
.
.
lea dx,filename
call fexist
jnc got_the_file ; if CF = 0, go on
jmp doserror ; else go to error handling code
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FFLUSH: flushes the DOS output buffer for specified handle
Source: fflush.asm
Call with: BX = file handle
flushing the buffer guards against data loss in case of system
failure, such as power loss
Returns: if CF = 0, no error; function successful
if CF = 1, AX = DOS error code
Uses: AX, flags
Example:
include asm.inc
extrn fflush:proc
.code
; program opens file & writes to file
.
.
mov bx,handle
call fflush
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FGETSTR: read an ASCII string from an open file
Source: fgetstr.asm
Call with: BX = file handle
ES:[DI] pointing to memory buffer
CX = byte length of buffer
ASCII strings may be terminated with either 0Dh or 0Dh+0Ah.
After reading each string, FGetStr positions the file pointer
to read the next string. The memory buffer should be at
least 2 bytes longer than the longest string you expect to
read.
Returns: if CF = 0, CX = length of ASCII string
if CX = byte length of buffer, string >= size of buffer
if CF = 1, AX = DOS error code
if AX = 0, you've reached the end of the file
Uses: AX, CX, CF; all other registers and flags are saved
Example:
include asm.inc
extrn fgetstr:proc
.data
strbuffer db 102 dup (0) ; maximum string length is 100
.code
; program opens file with read or read/write access
.
.
.
mov bx,file_handle
mov cx,102 ; buffer size
push ds
pop es ; ES = DS
lea di,strbuffer ; ES:[DI] points to start of buffer
call fgetstr
jc oops
mov bx,di ; minor parameter juggling
call strndup ; make a copy in near heap so I can re-use
; the buffer
.
.
.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FILELIST: creates a list of file names matching a filespec mask
Source: filelist.asm (fcount.asm, dosalloc.asm)
Call with: DS:[SI] pointing to filespec mask
CX = file attribute mask
Returns: if CF = 0:
ES = base segment address of list buffer
AX = number of filenames in list
CX = list field width
if CF = 1, AX = MS-DOS error code
You should use DOS function 49h to release the file list
buffer when you're done with it.
Uses: AX, CX, ES, CF
Example:
include asm.inc
public myproc
.data
filespec db '*.*',0
.code
; program fragment assumes DS:@data
.
.
.
lea si,filespec
mov cx,16 ; normal files and subdirectories
call filelist
jc cant_do_it ; oops
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FINDDATE: given a successful call to FindFirst or FindNext, returns
the file's date stamp
Source: findfile.asm
Call with: DS:[BX] pointing to DTA buffer; assumes DS @DATA
Returns: DX = month
AX = day
CX = year
Uses: AX, CX, DX, flags
Example:
.code
; program fragment assumes DS:@data
.
.
.
lea bx,filespec
mov cx,0 ; normal files only
call findfirst ; find first matching file
jc no_more_files
cmp ax,-1
je no_more_files
call finddate
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FINDFIRST: This subroutine, when used with FindNext, finds files on
a disk which match an ASCIIZ filespec string. The filespec
string may contain the '*' and '?' wildcards.
Source: findfile.asm (heap.asm)
Call with: DS:[BX] pointing to ASCIIZ filespec string; assumes DS:@data
CX = file attribute mask
FindFirst allocates space for a local DTA buffer from the
near heap. See FindNext; also see HINIT.
Returns: AX = error code
-1 = insufficient memory in near heap (128 bytes required)
0 = no error
CF = 1 if no files match the filespec string
DS:[BX] -> DTA buffer if the subroutine is successful. Do not
alter the 128 bytes in the DTA buffer.
The name of the file is an ASCIIZ string at 30[BX]
The file attribute is a byte at 21[BX]
The low word of the file's size is at 26[BX]
The high word of the file's size is at 28[BX]
Uses: AX, BX, flags
Example:
.code
; program fragment assumes DS:@data
.
.
.
lea bx,filespec
mov cx,0 ; normal files only
call findfirst ; find first matching file
jc no_more_files
cmp ax,-1
je no_memory ; memory not available
; print the filename on the screen
tprint_next:
mov si,bx
add si,30 ; point to filename in DTA buffer
mov dh,count ; row value
mov dl,0 ; column 0
mov ah,12 ; color attribute - RED!
call tprint ; display the file name on the screen
inc count ; next filename on next row
call findnext ; any more matching filenames?
jnc tprint_next
no_more_files:
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FINDNEXT: finds file matching search string; use after FindFirst.
used only after a successful call to FindFirst.
Source: findfile.asm (heap.asm)
Call with: no parameters; assumes DS:@data
FindNext de-allocates the DTA buffer space after the first
unsuccessful search for a matching file.
Returns: DS:[BX] -> DTA buffer
CF = 1 if no more files match the filespec string.
Uses: BX, flags
Example: see FindFirst.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FINDTIME: given a successful call to FindFirst or FindNext, returns
the file's time stamp
Source: findfile.asm
Call with: DS:[BX] pointing to DTA buffer; assumes DS:@data
Returns: DX = hour
AX = minute
CX = second
Uses: AX, CX, DX, flags
Example: lea bx,filespec
mov cx,0 ; normal files only
call findfirst ; find first matching file
jc no_more_files
cmp ax,-1
je no_more_files
call findtime
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FPUTCR: writes a CR+LF pair to a file at the current position in
the file; the file must have been opened with read or
read/write access
Source: fputcr.asm
Call with: BX = file handle
Returns: if CF = 1, AX = MS-DOS error code
if CF = 0, no error
Uses: AX, flags
Example: mov bx,handle
call fputcr
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
FSIZE: determines a file's size
Source: fsize.asm
Call with: BX = valid file handle
Returns: if CF = 0, DX:AX = file size (low word in AX)
if CF = 1, AX = MS-DOS error code
Uses: AX, DX, CF
Example:
include asm.inc
extrn fsize:proc
.data
filenam db 'ASMLIB.DOC',0 ; ASCIIZ filename
.code
.
.
.
lea dx,filenam ; point to filename
mov ax,3D00h ; MS-DOS open file function, read-only
int 21h
jc oops ; jump to error control
; else no problem - continue
mov bx,ax ; file handle in BX
call fsize
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
QFNAME: qualifies a filename
Source: qfname.asm
Call with: DS:[BX] pointing to a filename; the filename may contain
drive specification and/or complete or partial path name.
Drive specification and path name not required.
Returns: DS:[SI] pointing to the full DRIVESPEC:\PATH\FILENAME
CX = length of full filename
Note that DS:[SI] points to QFName's buffer space; the next
call to QFName will return a new filename at the same address.
Uses: SI, CX, flags
Example:
include asm.inc
.data
docs db '*.doc',0 ; search for .DOC files in current directory
.code
; program fragment assumes DS:@data
.
.
.
lea bx,docs
call qfname